<?php
/**
 * Zead
 *
 * LICENSE	
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.opensource.org/licenses/bsd-license.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to eu@marcelomx.com so we can send you a copy immediately.
 *
 * @category   Zead
 * @author     Marcelo Rodrigues Gonzaga <eu@marcelomx.com>
 * @copyright  Copyright (c) 2008 Marcelo Rodrigues Gonzaga
 * @link       http://code.google.com/p/zead 
 * @license    http://www.opensource.org/licenses/bsd-license.php     New BSD License
 *
 **/


/** @see Zead_Html_Filter_Abstract **/
require_once 'Zead/Html/Filter/Abstract.php';

/**
 * @category   Zead
 * @package    Zead_Html
 * @subpackage Zead_Html_Filter
 * @copyright  Copyright (c) 2008 Marcelo Rodrigues Gonzaga 
 * @license    http://www.opensource.org/licenses/bsd-license.php     New BSD License  
 */
class Zead_Html_Filter_PageOffline extends Zead_Html_Filter_Abstract
{
	/**
	 * Aplica o filtro que tem a função de procurar elementos com o id siteName ou outro
	 * passado como argumento que será o título do site.
	 * @param string $value O título do site
	 * @param string $id O id do elemento a ser alterado.
	 */
	public function filter() 
	{
		$pageOffline = $this->html->getElementById('pageOffline');
		
		if ($pageOffline) {
			$front = Zead_App_Front::getInstance();
			$form  = $pageOffline->appendChild($this->html->createElement('form'));
			$form->setAttribute('name', 'pageOffline');
			$form->setAttribute('action', '');
			$form->setAttribute('method', 'post');
			$form->setAttribute('target', '_blank');
			$select = $form->appendChild($this->html->createElement('select'));

			foreach ($front->metadata->resources->getChildren() as $resource) {
				$option = $select->appendChild($this->html->createElement('option'));
				$option->setAttribute('value', $resource->getAttribute('id'));
				$option->update($resource->getAttribute('title'));	
			}
			// Opção para PDF
			$span = $form->appendChild($this->html->createElement('span'));
			$span->update('Formato');
			$check = $form->appendChild($this->html->createElement('input'));
			$check->setAttribute('id', 'offlinePDF');
			$check->setAttribute('type', 'radio');
			$check->setAttribute('name', 'type');
			$check->setAttribute('value', 'PDF');
			$label = $form->appendChild($this->html->createElement('label'));
			$label->update('PDF');
			$label->setAttribute('for', 'offlinePDF');
			$check = $form->appendChild($this->html->createElement('input'));
			$check->setAttribute('id', 'offlineHTML');			
			$check->setAttribute('type', 'radio');
			$check->setAttribute('name', 'type');
			$check->setAttribute('value', 'HTML');
			$check->setAttribute('checked', 'checked');
			$label = $form->appendChild($this->html->createElement('label'));
			$label->update('HTML');
			$label->setAttribute('for', 'offlineHTML');
			// Botão submit
			$button = $form->appendChild($this->html->createElement('input'));
			$button->setAttribute('type','submit');
			$button->setAttribute('value', 'Gerar');			
		}
	}
}
